import { _decorator, Component, Node, Sprite, SpriteFrame, v3, Vec3 } from 'cc';
import { GameManager } from '../GameManager';
import { CarriageSF } from '../../AshFramework/Datas/GameConstant';
import { BundleManager } from '../../AshFramework/Managers/BundleManager';
const { ccclass, property } = _decorator;

const roofPos: Vec3[] = [v3(-27, 50), v3(-27, 230), v3(-27, 410), v3(-27, 590)];

const carriagerLayerPos: Vec3[] = [v3(0, 110), v3(0, 290), v3(0, 470)];
@ccclass('UIChariot')
export class UIChariot extends Component {
    @property({ type: [Node] })
    ArrCarriage: Node[] = [];

    @property(Node)
    RoofNode: Node = null;

    show() {
        let arrWeapon = GameManager.Instance.userData.weapon;
        let index: number = 0;
        for (let i = 0; i < arrWeapon.length; i++) {
            if (arrWeapon[i] != 0) {
                this.ArrCarriage[index].active = true;
                let name = CarriageSF[GameManager.Instance.userData.epoch][arrWeapon[i] - 1];
                if (!name) continue;
                this.ArrCarriage[index].getComponent(Sprite).spriteFrame = BundleManager.AssetMap.get(name) as SpriteFrame;
                index++;
            }
        }
        this.RoofNode.position = roofPos[index];
    }

    protected onEnable(): void {
        this.show();
    }


}


